package org.jaaksi.demo.animator;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;

/**
 * Created by Fcy on 2016/8/28.
 */
public class ZanActivity extends Activity implements View.OnClickListener {

    private ImageView imageView;
    private ValueAnimator animator;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zan);

        imageView = (ImageView) findViewById(R.id.iv_zan);
        animator = ObjectAnimator.ofFloat(1, 1.5f, 0.8f, 1);
        animator.setDuration(1500);
        animator.setInterpolator(new AccelerateInterpolator());
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                imageView.setSelected(!imageView.isSelected());
            }

            @Override
            public void onAnimationEnd(Animator animation) {
//                imageView.setSelected(!imageView.isSelected());
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                imageView.setScaleX(value);
                imageView.setScaleY(value);
            }
        });
        imageView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        animator.start();
    }
}